package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.mall.dto.ProductDetailRequest;
import com.cskaoyan.mall.dto.ProductDetailResponse;

import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author llf
 * @Date 2022/6/19 20:11
 */
@RestController
public class ProductDetailController {
    @Autowired
    IProductService iProductService;
    @GetMapping("/shopping/product/{id}")
    public ResponseData shoppingProduct(@PathVariable ("id") Long id){
        ProductDetailRequest productDetailRequest=new ProductDetailRequest(id);
        ProductDetailResponse productDetail = iProductService.getProductDetail(productDetailRequest);
        if (ShoppingRetCode.SUCCESS.getCode().equals(productDetail.getCode())) {
            // 执行成功，直接返回前端需要的数据
            return new ResponseUtil().setData(productDetail.getProductDetailDto());
        }
        // 调用失败
        return new ResponseUtil().setErrorMsg(productDetail.getMsg());
    }
}
